document.write('\<script type=\"text\/javascript\" src=\"js\/xml.js\"\>\<\/script\>');
document.write('\<script type=\"text\/javascript\" src=\"js\/rgui.js\"\>\<\/script\>');

var detailxhr = false;

var msgObj;

function checkApply() {
	alert('TODO :check apply');
	return true;
}

function showTimeZoneSels() {
	var tzSel = document.getElementById('timezone');
	if (tzSel.getAttribute('class') == 'timezoneh') {
		tzSel.setAttribute('class', 'timezonev');
		tzSel.style.visibility = 'visible';
	} else {
		tzSel.setAttribute('class', 'timezoneh');
		tzSel.style.visibility = 'hidden';
	}
}

function showIDKeyDetails(keyid) {
	detailxhr = getXMLRequest();
	var url = document.URL.split('ibcid.jsp')[0] + 'id.do?action=idKeyDetails&id=' + keyid;
	detailxhr.onreadystatechange = idKeyDetailsCallback;
	detailxhr.open('GET', url, true);
	detailxhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	detailxhr.send(null);
	if (isIE())
		return;
	msgObj = createMsgBody(400, 100, 'msg', '50%', '35%', 'blue');
	var title = createTitle('\u8eab\u4efd\u6587\u4ef6\u4fe1\u606f', '', 'blue');
	msgObj.appendChild(title);
	document.body.appendChild(msgObj);
	var msgDiv = document.createElement('div');
	msgObj.appendChild(msgDiv);
	var progressDiv = document.createElement('div');
	progressDiv.style.textAlign = 'center';
	progressDiv.style.margin = '0px';
	progressDiv.appendChild(document.createTextNode('loading...'));
	var buttonDiv = document.createElement('div');
	var cancelBtn = document.createElement('input');
	cancelBtn.setAttribute('type', 'button');
	cancelBtn.setAttribute('value', '\u53d6\u6d88');//取消
	cancelBtn.setAttribute('name', 'cancel');
	cancelBtn.style.marginLeft = 'auto';
	cancelBtn.style.marginRight = 'auto';
	cancelBtn.onclick = function() {
		detailxhr.abort();
		document.body.removeChild(msgObj);
	};
	buttonDiv.appendChild(cancelBtn);
	msgDiv.appendChild(progressDiv);
	msgDiv.appendChild(buttonDiv);
}

function idKeyDetailsCallback() {
	if (detailxhr.readyState == 4) {
		if (detailxhr.status == 200) {
			var json = jsonParse(detailxhr.responseText);
			if (json.errcode == '0') {
				var detailDiv = document.createElement('div');
				detailDiv.setAttribute('align', 'center');
				detailDiv.style.marginTop = '10px';
				var dtlTable = document.createElement('table');
				dtlTable.style.border = '1px solid #cad9ea';
				dtlTable.style.color = '#666';
				dtlTable.style.tableLayout = 'fixed';
				dtlTable.style.emptyCells = 'show';
				dtlTable.style.borderCollapse = 'collapse';
				dtlTable.style.margin = '0 auto';
				var gedDt = document.createElement('tr');
				gedDt.style.backgroundColor = '#f5fafe';
				var gedDtTd0 = document.createElement('td');
				gedDtTd0.style.textAlign = 'left';
				gedDtTd0.style.border = '1px solid #cad9ea';
				gedDtTd0.style.padding = '0 1em 0';
				//创建日期
				gedDtTd0.appendChild(document.createTextNode('\u521b\u5efa\u65e5\u671f'));
				var gedDtTd1 = document.createElement('td');
				gedDtTd1.style.textAlign = 'left';
				gedDtTd1.style.border = '1px solid #cad9ea';
				gedDtTd1.style.padding = '0 1em 0';
				var dt = new Date();
				dt.setTime(json.genDate);
				gedDtTd1.appendChild(document.createTextNode(dt.toLocaleDateString()));
				gedDt.appendChild(gedDtTd0);
				gedDt.appendChild(gedDtTd1);
				dtlTable.appendChild(gedDt);
				var appTr = document.createElement('tr');
				var appTrTd0 = document.createElement('td');
				appTrTd0.style.textAlign = 'left';
				appTrTd0.style.border = '1px solid #cad9ea';
				appTrTd0.style.padding = '0 1em 0';
				//申请人
				appTrTd0.appendChild(document.createTextNode('\u7533\u8bf7\u4eba'));
				var appTrTd1 = document.createElement('td');
				appTrTd1.style.textAlign = 'left';
				appTrTd1.style.border = '1px solid #cad9ea';
				appTrTd1.style.padding = '0 1em 0';
				appTrTd1.appendChild(document.createTextNode(json.applicant));
				appTr.appendChild(appTrTd0);
				appTr.appendChild(appTrTd1);
				dtlTable.appendChild(appTr);
				var hUserTr = document.createElement('tr');
				hUserTr.style.backgroundColor = '#f5fafe';
				var hUserTrTd0 = document.createElement('td');
				hUserTrTd0.style.textAlign = 'left';
				hUserTrTd0.style.border = '1px solid #cad9ea';
				hUserTrTd0.style.padding = '0 1em 0';
				var hUserTrTd1 = document.createElement('td');
				hUserTrTd1.style.textAlign = 'left';
				hUserTrTd1.style.border = '1px solid #cad9ea';
				hUserTrTd1.style.padding = '0 1em 0';
				var hTimeTr = document.createElement('tr');
				var hTimeTrTd0 = document.createElement('td');
				hTimeTrTd0.style.textAlign = 'left';
				hTimeTrTd0.style.border = '1px solid #cad9ea';
				hTimeTrTd0.style.padding = '0 1em 0';
				var hTimeTrTd1 = document.createElement('td');
				hTimeTrTd1.style.textAlign = 'left';
				hTimeTrTd1.style.border = '1px solid #cad9ea';
				hTimeTrTd1.style.padding = '0 1em 0';
				var toowner = json.owner;
				var stampct = '\u4e0d\u5305\u542b\u65f6\u95f4\u6233';//没有时间戳
				if (json.hasTimeStamp == 'true') {
					var tmp = json.owner.split('#');
					toowner = tmp[0];
					stampct = tmp[1];
				}
				//用户
				hUserTrTd0.appendChild(document.createTextNode('\u7528\u6237'));
				//时间戳
				hTimeTrTd0.appendChild(document.createTextNode('\u65f6\u95f4\u6233'));
				hUserTrTd1.appendChild(document.createTextNode(toowner));
				hTimeTrTd1.appendChild(document.createTextNode(stampct));
				hUserTr.appendChild(hUserTrTd0);
				hUserTr.appendChild(hUserTrTd1);
				hTimeTr.appendChild(hTimeTrTd0);
				hTimeTr.appendChild(hTimeTrTd1);
				dtlTable.appendChild(hUserTr);
				dtlTable.appendChild(hTimeTr);
				var btnDiv = document.createElement('div');
				var tipSpan = document.createElement('span');
				tipSpan.appendChild(document.createTextNode('\u8bf7\u901a\u8fc7\u5ba2\u6237\u7aef\u4e0b\u8f7d'));
				btnDiv.appendChild(tipSpan);
				var okBtn = document.createElement('input');
				okBtn.setAttribute('type', 'button');
				okBtn.setAttribute('value', '\u786e\u5b9a');
				okBtn.style.marginLeft = 'auto';
				okBtn.style.marginRight = 'auto';
				okBtn.onclick = function() {
					document.body.removeChild(dtObj);
				};
				btnDiv.appendChild(okBtn);
				var helpLink = document.createElement('a');
				helpLink.setAttribute('href', 'help.html');
				helpLink.setAttribute('target', '_blank');
				helpLink.appendChild(document.createTextNode('\u4e0b\u8f7d\u5e2e\u52a9'));
				btnDiv.appendChild(helpLink);
				var dtObj = createMsgBody(400, 300, 'dt', '50%', '35%', 'blue');
				var title = createTitle('\u8eab\u4efd\u6587\u4ef6\u4fe1\u606f', 'dt', 'blue');
				detailDiv.appendChild(dtlTable);
				dtObj.appendChild(title);
				dtObj.appendChild(detailDiv);
				dtObj.appendChild(btnDiv);
				if (!isIE()) {
					document.body.removeChild(msgObj);
				}
				document.body.appendChild(dtObj);
			} else {
			}
		}
	}
}

// function removeDownloadButton(linka, keyid) {
	// linka.setAttribute('onclick', 'createDownloadButton(this, ' + keyid + ')');
	// var btnDiv = document.getElementById('downloadkey' + keyid);
	// btnDiv.innerHTML = '';
// }

// function createDownloadButton(linka, keyid) {
	// linka.setAttribute('onclick', 'removeDownloadButton(this, ' + keyid + ')');
	// var btnDiv = document.getElementById('downloadkey' + keyid);
	// var pwdipt = document.createElement('input');
	// pwdipt.setAttribute('type', 'password');
	// pwdipt.setAttribute('name', 'password');
	// var btnsbt = document.createElement('input');
	// btnsbt.setAttribute('type', 'submit');
	// btnsbt.setAttribute('name', 'download');
	// btnsbt.setAttribute('value', '\u4e0b\u8f7d');
	// var hidipt = document.createElement('input');
	// hidipt.setAttribute('type', 'hidden');
	// hidipt.setAttribute('name', 'id');
	// hidipt.setAttribute('value', keyid);
	// btnDiv.appendChild(document.createTextNode('\u8f93\u5165\u5bc6\u7801\uff1a'));
	// btnDiv.appendChild(document.createElement('br'));
	// btnDiv.appendChild(pwdipt);
	// btnDiv.appendChild(btnsbt);
	// btnDiv.appendChild(hidipt);
// }

function isIE() {
	var ua = navigator.userAgent.toLowerCase();
	if (window.ActiveXObject) {
		if (ua.match(/msie/)[0])
			return true;
	}
	return false;
}
